'use strict'
const fs = require('fs');

class sticker {

    __mid() {
        return [
            {
                name: 'user-verify',
                path: ['post', 'delete', 'get']
            }
        ]
    }

    constructor() {
        this.param = '/'
    }
    //创建资源
    async get(c) {
        try {
            var openid = c.box.user.openid;
            let r = await c.service.psql.query(`select user_id from users where openid = '${openid}'`);
            var user_id = r.rows[0].user_id;
            var r2 = await c.service.psql.query(`select * from user_${user_id}_pay_sti`);
            for(var i =0;i<r2.rowCount;i++){
                var r3 = await c.service.psql.query(`select sticker_name from sticker where sticker_id = ${r2.rows[i].sticker_id}`);
                r2.rows[i].name= r3.rows[0].sticker_name;
            }
            return c.send(r2.rows);
        } catch (err) {
            console.log(err);
            return c.status(500).send('error');
        }
    }

}


module.exports = sticker